package com.mobipe.sutto.messagehandler;

/**
 * 
 */

import java.lang.reflect.Field;
import java.nio.channels.Channel;

/**
 * @author kohachiro
 * 
 */
public interface MessageHandler {
	static class GetRequestName {
		public static String findName(int Method) {
			Class<MessageHandler> c = MessageHandler.class;
			Field[] fields = c.getFields();
			for (int i = 0; i < fields.length; i++) {
				try {
					if (fields[i].getShort(c) == Method) {
						return fields[i].getName();
					}
				} catch (Exception e) {
					continue;
				}
			}

			return InvidRequest;
		}
	}
	//                1110 0000 0000 0000
	//                ^-- others can to see 1=can 0=can't
	//                 ^-- decode message 1=don't deocde 0=deocde
	public final static String InvidRequest 			= "InvidRequest";

	public final static short HttpGetRequest			= 0x4745;//0100 0111 0100 0101	0x47455420 
	public final static short HttpPostRequest			= 0x504F;//0101 0000 0100 0111	0x504F5354
	
	public final static short ChangeRoomRequest 		= -15000;//1100 0101 0110 1000
	public final static short JoinDefaultRoomRequest 	= -15001;
	public final static short LogoutRequest				= -15002;
	public final static short ZoneMessageRequest 		= -15003;
	public final static short ServerMessageRequest 		= -15004;	
	public final static short CorePropertyUpdateRequest	= -15005;
	
	public final static short PrivateMessageRequest		= 2000;
	public final static short ExtPropertyUpdateRequest	= 21;	
	public final static short JoinServerRequest 		= 22;//
	public final static short ClientInfoRequest			= 23;//0000 0001
	public final static short GetRoomListRequest 		= 24;//1100 0010
	public final static short GetUserListRequest 		= 25;
	public final static short GetZoneListRequest		= 26;
	public final static short NetSpeedRequest			= 27;
	public final static short PingIntervalRequest		= 28;
	public final static short SendMessageRequest 		= 29;
	public final static short CallRPCRequest 			= 30;
	
	public final static short CallRPCResponse 			= 31;	
	public final static short NewMessageResponse 		= 32;
	public final static short CertificateResponse 		= 40;
	public final static short ChangeRoomFailedResponse 	= 41;
	public final static short ChangeRoomSucceedResponse = 42;
	// public final static short JoinRoomFailedResponse = 43;
	public final static short JoinRoomSucceedResponse	= 44;
	// public final static short JoinServerFailedResponse=45;
	public final static short JoinServerSucceedResponse = 46;
	public final static short NewUserResponse 			= 47;
	public final static short RoomListResponse 			= 48;
	public final static short ServerErrorResponse 		= 49;
	public final static short TimeStampResponse 		= 50;
	public final static short UserLeaveResponse 		= 51;
	public final static short UserListResponse 			= 52;
	public final static short ZoneListResponse 			= 53;

	public final static short ServerTimeResponse		= 60;
	public final static short DisconnectedRequest		= 99;

	public final static byte ROUTER_USER = -1;
	public final static byte ROUTER_ROOM = -2;
	public final static byte ROUTER_ZONE = -3;
	public final static byte ROUTER_SERVER = -4;
	
	public final static byte STATUS_OK = -11;

	public final static byte STATUS_ROOM_FULL = -13;
	public final static byte STATUS_ROOM_LOCKED = -14;
	public final static byte STATUS_ROOM_NOT_FOUND = -15;
	public final static byte STATUS_ROOM_NEEDPASWORD = -16;
	public final static byte STATUS_ROOM_CREATE_FAILED = -12;
	public final static byte STATUS_ROOM_TEMPLATE_NOT_FOUND = -17;

	public final static byte STATUS_SERVER_FULL = -18;
	public final static byte STATUS_NAME_CONTAINS_BAD_WORD = -19;
	public final static byte STATUS_NAME_USED = -20;

	public final static byte STATUS_FAILED = -23;
	public final static byte STATUS_AUTH_FAILED = -24;
	public final static byte STATUS_INVID_REQUEST = -25;
	public final static byte STATUS_INVID_REQUEST_DATA = -26;
	public final static byte STATUS_INTERNAL_ERROR = -27;
	public final static byte STATUS_UNKNOWN_ERROR = -28;
	public final static byte STATUS_EXPIRED_CERTIFICATE = -29;

	/**
	 * 
	 * @param Method
	 * @return
	 */
	public abstract int invoke(Object data, Channel channel) throws Exception;

}
